//
//  Tweet_RootViewController.m
//  Coding_My
//
//  Created by showXxie on 2017/8/21.
//  Copyright © 2017年 sooxie. All rights reserved.
//

#import "Tweet_RootViewController.h"
#import "TweetCell.h"
#import "Tweet.h"

@interface Tweet_RootViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, assign) NSInteger curIndex;
@property (nonatomic, strong) NSMutableDictionary *tweetsDict;
@property (nonatomic, strong) UITableView *myTableView;

@property (nonatomic, strong) ODRefreshControl *refreshControl;

@end

//冒泡
@implementation Tweet_RootViewController


+ (instancetype)newTweetVCWithType:(Tweet_RootViewControllerType)type{
    Tweet_RootViewController *vc = [Tweet_RootViewController new];
    vc.curIndex = type;
    return vc;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _curIndex = 0;
//        _tweetsDict = [[NSMutableDictionary alloc] initWithCapacity:4];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.view.backgroundColor = [UIColor orangeColor];
    
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"hot_topic_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(hotTopicBtnClicked:)];
    
    [self.parentViewController.navigationItem setLeftBarButtonItem:leftBarItem animated:NO];
    
    _tweetsDict = [[NSMutableDictionary alloc] initWithCapacity:4];
    
    
    _myTableView = ({
        UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        tableView.backgroundColor = [UIColor greenColor];
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        Class tweetCellClass = [TweetCell class];
        [tableView registerClass:tweetCellClass forCellReuseIdentifier:kCellIdentifier_Tweet];
        [self.view addSubview:tableView];
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
        tableView;
    });


}

#pragma mark TableM
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
 
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TweetCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_Tweet forIndexPath:indexPath];
    Tweet *tweet = [[Tweet alloc] init];
    tweet.content = @"江天水电费撒旦法嘎斯搭噶是的古典风格是非观电饭锅第三方";
    tweet.location = @"北京三里屯";
    tweet.device =@"iphone8";
    tweet.liked = @0;
    tweet.likes = @3;
    [cell setTweet:tweet needTopView:YES];
    
    
    __weak typeof(self) weakSelf = self;

    cell.cellRefreshBlock = ^(){
        [weakSelf.myTableView reloadData];
    };
    return cell;

    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    Tweet *tweet = [[Tweet alloc] init];
    tweet.content = @"江天水电费撒旦法嘎斯搭噶是的古典风格是非观电饭锅第三方";
    tweet.location = @"北京三里屯";
    tweet.device =@"iphone8";
    tweet.liked = @0;
    tweet.likes = @3;
    
    return [TweetCell cellHeightWithObj:tweet needTopView:YES];

}


- (void)hotTopicBtnClicked:(id)sender{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
